package top.buluoluo.ordersservice.enums;

import lombok.Getter;

@Getter
public enum OrderDeliveryMethod {
    EXPRESS("快递配送"),
    SELF_PICKUP("用户自提");

    private final String description;

    OrderDeliveryMethod(String description) {
        this.description = description;
    }

    /**
     * 安全转换方法
     * @param value 数据库存储值
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果值无效
     */
    public static OrderDeliveryMethod fromValue(String value) {
        for (OrderDeliveryMethod method : values()) {
            if (method.name().equalsIgnoreCase(value)) {
                return method;
            }
        }
        throw new IllegalArgumentException("未知配送方式: " + value);
    }

    /**
     * 检查是否需要配送地址
     */
    public boolean requiresDeliveryAddress() {
        return this == EXPRESS;
    }

    /**
     * 检查是否需要自提点信息
     */
    public boolean requiresPickupLocation() {
        return this == SELF_PICKUP;
    }
}